{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "98dd1e48",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    " >  1.函数的定义\n",
    " \n",
    " >  2.如何使用函数\n",
    " \n",
    " >  3.函数的返回值\n",
    " \n",
    " >  4.使用注释改进文档\n",
    " \n",
    " >  5.传递任意数量的实参\n",
    " \n",
    " >  6.函数与模块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17b8cd86",
   "metadata": {},
   "source": [
    "## 1.函数的定义\n",
    "\n",
    "* 定义函数：\n",
    "> 1.写def:def定义函数的第一步\n",
    "\n",
    "> 2.写定义函数的名称：def function_name\n",
    "\n",
    ">> 1.function_name 遵循变量名称定义的规则\n",
    "\n",
    "> 3.函数名称后加上\"():\":def function_name()===> f(x) = 2x\n",
    "\n",
    "* 书写函数体\n",
    "> 1.函数的注释\n",
    "> 2.写函数的具体操作（函数体）\n",
    "> 3.注意：函数也是需要有tab 键的间距\n",
    "\n",
    "* 使用函数（函数的调用）\n",
    "> 1.function_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6c333a1d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def fib(n):     #write Fibonacci series up to n\n",
    "    \"\"\"Print a Fibonacci series up to n.\"\"\"\n",
    "    a,b =0,1\n",
    "    while a < n:\n",
    "        print(a,end='')\n",
    "        a,b = b,a+b\n",
    "        print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5fdd0e1a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "1\n",
      "2\n",
      "3\n",
      "5\n",
      "8\n"
     ]
    }
   ],
   "source": [
    "fib(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "1bebc6cc",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 尝试： 写一个实现hello world 的函数\n",
    "def hello():     #write Fibonacci series up to n\n",
    "    \"\"\"打印hello world\"\"\"\n",
    "    print(\"hello world!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5447f1fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "hello()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c7c3aefa",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 思考函数存在的意义？"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
